package com.example.day4_week1;

import android.app.Activity;
import android.content.Context;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.bumptech.glide.Glide;

import java.util.List;
import java.util.Timer;

import androidx.viewpager.widget.ViewPager;

public class MyAdapter extends BaseAdapter {
    private List<FoodEntity.DataBean> list;
    private Context context;
    int num;
    long time1,time2;



    public MyAdapter(List<FoodEntity.DataBean> list, Context context) {
        this.list = list;
        this.context = context;
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {
        ViewHolder viewHolder = null;
        if(convertView == null){
            viewHolder = new ViewHolder();
            convertView = LayoutInflater.from(context).inflate(R.layout.item,null);
            viewHolder.imageView = convertView.findViewById(R.id.iv);
            viewHolder.textView = convertView.findViewById(R.id.tv);
            convertView.setTag(viewHolder);

        }else{
            viewHolder  = (ViewHolder) convertView.getTag();
        }
        viewHolder.textView.setText(list.get(position).getNum()+"");
        Glide.with(context).load(list.get(position).getPic()).into(viewHolder.imageView);









        return convertView;
    }

    class  ViewHolder{
        ImageView imageView;
        TextView textView;
    }


}
